﻿using System;
using System.Collections.Generic;
using System.Text;
using ZLDC.Common.Estate;
using System.Data.SqlClient;
using System.Data;
using ZLDC.Topo.Model.Estate;


namespace ZLDC.DAL.Estate
{
    public  class EstatepicDAL
    {
                                                                                public static int SavePic(List<Thumbnail> list, string type, int eid, string ename, int bid, string bname, string[] Array, string[] Array1, string userid, string username, string deptid, string deptname)
        {
            int rows=0;

            using (_Database db = new _Database("estate"))
            {
                string sql = string.Empty;
                int i = 0;
                foreach (Thumbnail item in list)
                {

                    sql += "insert into t_estate_pic values('" + item.ImagePath + "','" + item.Name + "','" + type + "','" + eid + "','" + ename + "','" + bid + "','" + bname + "','" + Array[i] + Array1[i] + "', '" + deptid + "', '" + deptname + "', '" + userid + "', '" + username + "','" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "');";
                    i = i + 1;
                }
                rows = db.ExecuteSql(sql);
            }
          
            return rows;
        }

                                                                public static DataTable p_estate_pic_listall_table(int eid, int type, _Database db)
        {
            List<SqlParameter> parms = new List<SqlParameter>();

            parms.Add(new SqlParameter("@eid", eid));
            parms.Add(new SqlParameter("@type", type));
            SqlParameter pRetval = new SqlParameter("@retval", SqlDbType.Int, 4);
            pRetval.Direction = ParameterDirection.ReturnValue;
            parms.Add(pRetval);

            DataTable dt = null;
            dt = db.GetDataTable("p_estate_pic_listall", parms);

            int retval = (pRetval.Value == System.DBNull.Value) ? 0 : Convert.ToInt32(pRetval.Value);

            return dt;
        }

                public static int DelPic(int id, int deptid, _Database db)
        {
            int rows = 0;
            try
            {
                string sql = "";
                if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("删除图片"))                {
                    sql = "delete from t_estate_pic where id=" + id + "";
                }
                else
                {
                    string IdList = ZLDC.Common.BaseUser.UserInfo.getAllChildDept(_Utility.GetInfoBySession().m_sDeptID, _Utility.GetInfoBySession().m_sUserID);

                    sql = "delete from t_estate_pic where id=" + id + " and deptid in(" + IdList + ")";
                }
                rows = db.ExecuteSql(sql);
            }
            catch
            {

            }
            finally
            {
                db.close();
            }
            return rows;
        }
    
    }
}
